package com.ecp.commons.bean;

import java.util.ArrayList;
import java.util.List;

import com.ecp.commons.annotation.VariantType;
import com.ecp.commons.serialization.GenericBean;
import com.ecp.commons.serialization.Variant;

public class Column extends GenericBean {

	public static int	NEEDCERTIFY_YES		= 1;
	public static int	NEEDCERTIFY_NO		= 0;
	public static int	MERCHANT_ROOT_ID	= 2801;

	@Override
	public void defineVariantSet() {
		this.entity = "t_column";
		map.put("id", new Variant().setType(VariantType.INTEGER).setNullable(false).setPk(true));
		map.put("innerName", new Variant().setLength(64).setNullable(false));
		map.put("outerName", new Variant().setLength(1024));
		map.put("parentId", new Variant().setType(VariantType.INTEGER).setNullable(false));
		map.put("columnDesc", new Variant().setLength(255));
		map.put("columnTypeId", new Variant().setType(VariantType.INTEGER).setNullable(false));
		map.put("needCertify", new Variant().setType(VariantType.INTEGER).setNullable(false));
		map.put("ctxData", new Variant().setLength(1024));
		map.put("isInhert", new Variant().setType(VariantType.INTEGER).setNullable(false));
		map.put("columnHomeUrl", new Variant().setLength(128));
		map.put("columnNarticleUrl", new Variant().setLength(128));
		map.put("colOrder", new Variant().setType(VariantType.INTEGER).setNullable(false));
		map.put("published", new Variant().setType(VariantType.INTEGER));
		map.put("shortName", new Variant().setLength(1024));
		map.put("isFrontShow", new Variant().setType(VariantType.INTEGER));
		map.put("columnStyle", new Variant().setLength(128));
		map.put("merchantId", new Variant().setType(VariantType.INTEGER));
		map.put("isFreeze", new Variant().setLength(5));
		map.put("a_imgPath", new Variant().setLength(255));
		map.put("path", new Variant().setLength(255));
		map.put("channelId", new Variant().setType(VariantType.INTEGER).setNullable(false)); //分类对应的频道页的columnId
	}

	@Override
	public void resetValues() {
		set("parentId", 0);
		set("columnTypeId", 0);
		set("needCertify", 0);
		set("innerName", "");
		set("isInhert", 1);
		set("colOrder", 0);
		set("published", 1);
		set("merchantId", 0);
		set("isFreeze", 0);
		set("channelId", 0);
	}

	List<Column>	childrens	= new ArrayList<Column>();

	public List<Column> getChildrens() {
		return childrens;
	}

	public void setChildrens(List<Column> childrens) {
		this.childrens = childrens;
	}

	public int getId() {
		return this.getInt("id");
	}

	public String getInnerName() {
		return this.getString("innerName");
	}

	public String getOuterName() {
		return this.getString("outerName");
	}

	public int getParentId() {
		return this.getInt("parentId");
	}

	public String getColumnDesc() {
		return this.getString("columnDesc");
	}

	public int getColumnTypeId() {
		return this.getInt("columnTypeId");
	}

	public int getNeedCertify() {
		return this.getInt("needCertify");
	}

	public String getCtxData() {
		return this.getString("ctxData");
	}

	public int getIsInhert() {
		return this.getInt("isInhert");
	}

	public String getColumnHomeUrl() {
		return this.getString("columnHomeUrl");
	}

	public String getColumnNarticleUrl() {
		return this.getString("columnNarticleUrl");
	}

	public int getColOrder() {
		return this.getInt("colOrder");
	}

	public int getPublished() {
		return this.getInt("published");
	}

	public String getShortName() {
		return this.getString("shortName");
	}

	public int getIsFrontShow() {
		return this.getInt("isFrontShow");
	}

	public String getColumnStyle() {
		return this.getString("columnStyle");
	}

	public int getMerchantId() {
		return this.getInt("merchantId");
	}

	public String getIsFreeze() {
		return this.getString("isFreeze");
	}

	public String getA_imgPath() {
		return this.getString("a_imgPath");
	}

	public List<Integer> getPathIds() {
		List<Integer> pathIds = new ArrayList<Integer>();
		String path = this.getString("path");
		String[] ids = path.split("/");
		ids[0] = "0"; // 分割后第一个是空字串，直接赋值0，也好用于追溯和转换成int数组。
		for (String id : ids) {
			pathIds.add(Integer.valueOf(id));
		}
		return pathIds;
	}

	public int getLevel() {
		return this.getString("path").split("/").length;
	}

	public int getChannelId() {
		return this.getInt("channelId");
	}

	public void setId(int id) {
		this.set("id", id);
	}

	public void setInnerName(String innerName) {
		this.set("innerName", innerName);
	}

	public void setOuterName(String outerName) {
		this.set("outerName", outerName);
	}

	public void setParentId(int parentId) {
		this.set("parentId", parentId);
	}

	public void setColumnDesc(String columnDesc) {
		this.set("columnDesc", columnDesc);
	}

	public void setColumnTypeId(int columnTypeId) {
		this.set("columnTypeId", columnTypeId);
	}

	public void setNeedCertify(int needCertify) {
		this.set("needCertify", needCertify);
	}

	public void setCtxData(String ctxData) {
		this.set("ctxData", ctxData);
	}

	public void setIsInhert(int isInhert) {
		this.set("isInhert", isInhert);
	}

	public void setColumnHomeUrl(String columnHomeUrl) {
		this.set("columnHomeUrl", columnHomeUrl);
	}

	public void setColumnNarticleUrl(String columnNarticleUrl) {
		this.set("columnNarticleUrl", columnNarticleUrl);
	}

	public void setColOrder(int colOrder) {
		this.set("colOrder", colOrder);
	}

	public void setPublished(int published) {
		this.set("published", published);
	}

	public void setShortName(String shortName) {
		this.set("shortName", shortName);
	}

	public void setIsFrontShow(int isFrontShow) {
		this.set("isFrontShow", isFrontShow);
	}

	public void setColumnStyle(String columnStyle) {
		this.set("columnStyle", columnStyle);
	}

	public void setMerchantId(int merchantId) {
		this.set("merchantId", merchantId);
	}

	public void setIsFreeze(String isFreeze) {
		this.set("isFreeze", isFreeze);
	}

	public void setA_imgPath(String a_imgPath) {
		this.set("a_imgPath", a_imgPath);
	}

	public void setChannelId(int channelId) {
		this.set("channelId", channelId);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + getId();
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Column other = (Column) obj;
		if (getId() != other.getId())
			return false;
		return true;
	}
}
